package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏西西
 * Date: 2023-09-01
 * Time: 8:31
 */
public class ThreadDemo18 {
    //当前有三个线程，分别只能打印A,B,C控制三个线程按照固定的ABC来打印
    public static void main(String[] args) throws InterruptedException {
        Object locker1 = new Object();
        Object locker2 = new Object();

        Thread t1 = new Thread(() ->{
            synchronized (locker1) {
                locker1.notify();
            }
            System.out.println("A");
        });
        Thread t2 = new Thread(() ->{
            try {
                synchronized (locker1) {
                    locker1.wait();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("B");
            synchronized (locker2) {
                locker2.notify();
            }

        });
        Thread t3 = new Thread(() ->{
            try {
                synchronized (locker2) {
                    locker2.wait();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("C");
        });


        t2.start();
        t3.start();
        Thread.sleep(1000);

        t1.start();


    }
}
